/*
 * tetrixpiece.h - The individual tetrix pieces are defined here
 * Copyright (C) 2006-2007  Mithin Kumar L
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this application; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#ifndef TETRIXPIECE_H
#define TETRIXPIECE_H

enum TetrixShape {
				NoShape = -1,
				SquareShape,
				LineShape, 
				TShape, 
				LShape, 
				MirroredLShape,
				ZShape, 
				SShape
				};

static const int coordsTable[8][4][4][2] ={
	{
		{ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } },
		{ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } },
		{ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } },
		{ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } }
	},

	{
		{ { 1, 2 }, { 2, 2 }, { 1, 1 }, { 2, 1 } },
		{ { 1, 2 }, { 2, 2 }, { 1, 1 }, { 2, 1 } },
		{ { 1, 2 }, { 2, 2 }, { 1, 1 }, { 2, 1 } },
		{ { 1, 2 }, { 2, 2 }, { 1, 1 }, { 2, 1 } }
	},

	{
        { { 0, 1 }, { 1, 1 }, { 2, 1 }, { 3, 1 } },
		{ { 1, 3 }, { 1, 2 }, { 1, 1 }, { 1, 0 } },
		{ { 0, 1 }, { 1, 1 }, { 2, 1 }, { 3, 1 } },
		{ { 1, 3 }, { 1, 2 }, { 1, 1 }, { 1, 0 } }
	},

	{
        { { 0, 2 }, { 1, 2 }, { 2, 2 }, { 1, 1 } },
		{ { 2, 2 }, { 1, 3 }, { 1, 2 }, { 1, 1 } },
		{ { 1, 3 }, { 0, 2 }, { 1, 2 }, { 2, 2 } },
		{ { 0, 2 }, { 1, 3 }, { 1, 2 }, { 1, 1 } }
	},

	{
        { { 0, 2 }, { 1, 2 }, { 2, 2 }, { 0, 1 } },
		{ { 1, 3 }, { 1, 2 }, { 1, 1 }, { 2, 1 } },
		{ { 0, 2 }, { 2, 3 }, { 2, 2 }, { 1, 2 } },
		{ { 0, 3 }, { 1, 3 }, { 1, 2 }, { 1, 1 } }
	},

	{
     	{ { 2, 2 }, { 1, 2 }, { 0, 2 }, { 2, 1 } },
		{ { 2, 3 }, { 1, 3 }, { 1, 2 }, { 1, 1 } },
		{ { 0, 3 }, { 0, 2 }, { 1, 2 }, { 2, 2 } },
		{ { 1, 3 }, { 1, 2 }, { 1, 1 }, { 0, 1 } }
	},

	{
        { { 0, 2 }, { 1, 2 }, { 1, 1 }, { 2, 1 } },
		{ { 0, 1 }, { 0, 0 }, { 1, 2 }, { 1, 1 } },
		{ { 0, 2 }, { 1, 2 }, { 1, 1 }, { 2, 1 } },
		{ { 0, 1 }, { 0, 0 }, { 1, 2 }, { 1, 1 } }
	},

	{
        { { 1, 2 }, { 2, 2 }, { 0, 1 }, { 1, 1 } },
		{ { 2, 1 }, { 2, 0 }, { 1, 2 }, { 1, 1 } },
		{ { 1, 2 }, { 2, 2 }, { 0, 1 }, { 1, 1 } },
		{ { 2, 1 }, { 2, 0 }, { 1, 2 }, { 1, 1 } }
	}
};

class TetrixPiece
{
public:
	TetrixPiece();

    void setRandomShape();
    void setShape(TetrixShape shape);

    TetrixShape shape() const;
    int x(int index) const;
    int y(int index) const;
    int minX() const;
    int maxX() const;
    int minY() const;
    int maxY() const;
    //TetrixPiece rotatedLeft() const;
    //TetrixPiece rotatedRight() const;

	void rotate(const int direction,bool idle = false);

private:
    void setX(int index, int x) { coords[index][0] = x; }
    void setY(int index, int y) { coords[index][1] = y; }

    TetrixShape pieceShape;
	int rStatus;
    int coords[4][2];
};

#endif